package com.swpu.eduservice.controller.front;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swpu.commonutils.CourseWebVoOrder;
import com.swpu.commonutils.R;
import com.swpu.eduservice.entity.EduCourse;
import com.swpu.eduservice.entity.vo.CourseQueryVo;
import com.swpu.eduservice.entity.vo.CourseWebVo;
import com.swpu.eduservice.service.EduCourseService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 功能描述：
 *
 * @Author: ygq
 * @Date: 2021/10/28 20:01
 */
@RestController
@CrossOrigin
@RequestMapping("/eduservice/coursefront")
public class CourseFrontController {
    @Autowired
    private EduCourseService courseService;

    @PostMapping("getFrontcourseList/{page}/{limit}")
    public R getCourseList(@PathVariable long page,@PathVariable long limit,@RequestBody(required = false) CourseQueryVo courseQuery) {
            Page<EduCourse> pageParam = new Page<>(page, limit);
            Map<String, Object> map = courseService.pageListWeb(pageParam, courseQuery);
            return R.ok().data(map);
        }

        //根据课程ID查询课程信息
    @PostMapping("getCourseInfo/{id}")
    public CourseWebVoOrder getInfo(@PathVariable("id") String courseId){
        CourseWebVo courseWebVo = courseService.selectInfoWebById(courseId);
        CourseWebVoOrder courseWebVoOrder = new CourseWebVoOrder();
        BeanUtils.copyProperties(courseWebVo,courseWebVoOrder);
        return courseWebVoOrder;
    }
    }